export const staticRoutes = [
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login/index.vue'),
    meta: { hidden: true },
  },
  {
    path: '/404',
    component: () => import('@/views/error/404.vue'),
    meta: { hidden: true },
  },
  {
    path: '/',
    component: () => import('@/views/frontView/index.vue'),
    redirect: 'search', // 修改为相对路径
    children: [
      {
        path: 'search',
        name: 'Search',
        meta: { title: '搜索' },
        component: () => import('@/views/frontView/search/index.vue'),
      },
      {
        path: 'detail',
        name: 'Detail',
        meta: { title: '详情' },
        component: () => import('@/views/frontView/details/index.vue'),
      },
      {
        path: 'profile',
        name: 'Profile',
        meta: { title: '个人中心' },
        component: () => import('@/views/frontView/profile/index.vue'),
      },
    ],
  },
  {
    path: '/:pathMatch(.*)*',
    redirect: '/404',
    meta: { hidden: true },
  },
];

// 修复布局路由配置（关键修改1）
// 修改布局路由中的控制台配置
// 修改布局路由配置
export const layoutRoute = {
  path: '/dashboard',
  component: () => import('@/layouts/index.vue'),
  children: [
    {
      path: '',
      name: 'DashboardRoot',
      redirect: { name: 'DashboardIndex' }, // 直接重定向到命名路由
      component: () => import('@/views/dashboard/index.vue'),
      children: [
        // 控制台路由（核心修改）
        {
          path: 'index',
          name: 'DashboardIndex', // 使用更规范的命名
          component: () => import('@/views/dashboard/index/index.vue'),
          meta: { 
            title: '控制台',
            affix: true // 保持常驻标签页
          }
        },
        // 图书管理模块（示例）
        {
          path: 'books',
          component: () => import('@/views/dashboard/books/index.vue'),
          children: [
            {
              path: 'list',
              name: 'BookList',
              component: () => import('@/views/dashboard/books/list/index.vue'),
              meta: { title: '图书列表' }
            },
            {
              path: 'tags',
              name: 'BookTags',
              component: () => import('@/views/dashboard/books/tags/index.vue'),
              meta: { title: '标签管理' },
            },
          ],
        },
        {
          path: 'borrows',
          name: 'Borrows',
          component: () => import('@/views/dashboard/borrow/index.vue'),
          meta: { title: '借阅管理' },
          children: [
            {
              path: 'list',
              name: 'BorrowList',
              component: () => import('@/views/dashboard/borrow/list/index.vue'),
              meta: { title: '借阅列表' },
            },
          ],
        },
        {
          path: 'system',
          name: 'System',
          meta: { title: '系统管理', icon: 'system' },
          component: () => import('@/views/dashboard/system/index.vue'),
          children: [
            {
              path: 'users',
              name: 'SystemUsers',
              component: () => import('@/views/dashboard/system/user/index.vue'),
              meta: { title: '用户管理' },
            },
            {
              path: 'settings',
              name: 'SystemSettings',
              component: () => import('@/views/dashboard/system/setting/index.vue'),
              meta: { title: '系统设置' },
            },
          ],
        },
      ],
    }
  ]
};

// 移除重复的authRoutes配置
export const authRoutes = []; // 根据实际需要保留必要配置
// 其他路由保持扁平化结构...


// 在动态路由处理中增加默认路由匹配
permissionStore.routes.forEach(route => {
  router.addRoute('DashboardRoot', {
    ...route,
    path: route.path === '/dashboard' ? '/dashboard/index' : route.path
  });
});